<?php
/**
 * Created by 项目.
 * User: xuguopeng
 * Date: 2020-06-22
 * Time: 20:13
 * 提现操作
 */

namespace app\api\controller\v1;

use app\api\model\CityPartner;
use app\api\model\CountyPartner;
use app\api\model\ProvincePartner;
use app\api\service\withdrawal\WithdrawalSer;
use app\api\validate\withdrawal\CheckWithdrawal;
use think\facade\Request;
use app\api\service\Token;
use app\api\model\Withdrawal as WithdrawalModel;
use app\api\model\Assistant;

class Withdrawal
{
    // 申请提现
    public function setWithdrawal()
    {
        (new CheckWithdrawal())->goCheck();
        $post = Request::post();
        $Withdrawal = new WithdrawalSer($post);
        return $Withdrawal->entrance();
    }

    // 提现列表
    public function getWithdrawal($type)
    {
        $uid = Token::getCurrentUid();
        if($type == 1) {
            $id = $uid;
        } elseif ($type == 2) {
            $info = ProvincePartner::where('user_id',$uid)->find();
            $id = $info['id'];
        } elseif ($type == 3) {
            $info = CityPartner::where('user_id',$uid)->find();
            $id = $info['id'];
        } elseif ($type == 4) {
            $info = CountyPartner::where('user_id',$uid)->find();
            $id = $info['id'];
        } elseif ($type == 5) {
            $info = Assistant::where('user_id',$uid)->find();
            $id = $info['id'];
        }
        return WithdrawalModel::where('pid',$id)->where('type',$type)
            ->order('id desc')
            ->select()
            ->toArray();
    }
}